package net.realsee.gcl.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.util.IdUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.realsee.framework.core.domain.R;
import net.realsee.gcl.domain.bo.ccs.GclCcsOperateResult;
import net.realsee.gcl.domain.bo.ccs.GclCcsRequestParams;
import net.realsee.gcl.service.IGclCcsService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 协鑫CCS交互
 *
 * @author:
 * @date: 2023/08/28 上午 10:10
 **/
@SaIgnore
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/ccs")
public class GclCcsController {

    private final IGclCcsService iGclCcsService;

    /**
     * 上报CCS系统中库位可用状态
     */
    @PostMapping("/locationStatus")
    public R<Void> reportCcsLocationStatus(@RequestBody GclCcsRequestParams requestParams) {
        iGclCcsService.reportCcsLocationStatus(requestParams);
        return R.ok();
    }

    /**
     * 查询WCS系统中库位任务状态
     */
    @PostMapping("/taskStatus")
    public R<GclCcsOperateResult> queryWcsLocationTaskStatus(@RequestBody GclCcsRequestParams requestParams) {
        iGclCcsService.queryWcsLocationTaskStatus(requestParams);
        // TODO 要删除
        GclCcsOperateResult result = GclCcsOperateResult.builder().location(requestParams.getLocation()).taskCode(IdUtil.fastSimpleUUID()).build();
        if (requestParams.getType() == 10) {
            result.setTaskStatus("inbin");
        } else if (requestParams.getType() == 20) {
            result.setTaskStatus("outbin");
        } else if (requestParams.getType() == 30) {
            result.setTaskStatus("wait");
        }
        return R.ok(result);
    }

    /**
     * 上报CCS系统中库位内容器位置偏差数据
     */
    @PostMapping("/locationPosFix")
    public R<Void> reportContainerPosition(@RequestBody GclCcsRequestParams requestParams) {
        iGclCcsService.reportContainerPosition(requestParams);
        return R.ok();
    }
}
